home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH13
/
C13_4.ASM
< prev
next >
Wrap
Assembly Source File
|
1994-11-15
|
5KB
|
127 lines
;
; Program 13.4 Loading a Child
;
.286
dosseg
.model small
.stack 100h
.data
comm_tail db 3,' :',0Dh ; Command tail
prog_name db '\windows\win.com',0
; EXEC parameter block
align 2
Env dw 0 ; parent's environment
comlin dw offset comm_tail,0
FCB1 dw 5ch,0 ; 5Ch is FCB1 offset in PSP
FCB2 dw 6ch,0 ; 6Ch is FCB2 offset in PSP
SS_SP dw 0,0 ; Child's stack pointer
CS_IP dw 0,0 ; Child's entry point
ok_mess db 'Alright!',10,13,'$'
ret_val db 0
method db 0
.code
; Use code segment to store variables for invoking child program
;
save_ds dw 0 ; Parent's DS
save_sp dw 0 ; Parent's SP
save_ss dw 0 ; Parent's SS
child_ptr dw 0,0 ; Child's starting address
Start:
mov ax,@data
mov ds,ax ; Load data segment
call Init ; Resize program memory block
jnc Init_OK
jmp Exit ; Exit on error
Init_OK:
mov comlin+2,ds ; Load segment of command tail
mov FCB1+2,es ; Copy FCBs from parent's PSP
mov FCB2+2,es
mov ax,es:[2ch] ; Load environment segment
mov Env,ax ; from parent's PSP
mov ax,4b01h
mov dx,offset prog_name ; DS:DX points to child pathname
mov cx,ds
mov es,cx
mov bx,offset Env ; ES:BX points to EXEC parameter
; block
int 21h ; Load child
jc Exit ; CF set if error
mov cs:save_ds,ds ; Save DS in code segment
mov cs:save_ss,ss ; Save parent's stack pointer also
mov cs:save_sp,sp
mov ax,CS_IP ; Copy child pointer to code segment
mov child_ptr,ax ; so can reference it after changing
mov ax,CS_IP+2 ; DS, ES, SS
mov child_ptr+2,ax
mov ah,62h
int 21h ; Get current PSP (child's) in BX
cli
mov ss,SS_SP+2 ; Load child's stack
mov sp,SS_SP
sti
mov es,bx ; ES and DS must point to the
mov ds,bx ; child PSP before invoking it
; put return address in child's PSP
mov word ptr es:[10],offset cs:addr_back
mov es:[12],cs
jmp dword ptr cs:child_ptr ; Run child program
addr_back:
cli
mov ss,cs:save_ss ; Restore parent's stack
mov sp,cs:save_sp
sti
mov ds,cs:save_ds ; Restore parent's DS
mov ah,4dh
int 21h ; Get child-program return value
mov ret_val,al ; AL = return value
mov method,ah ; AH = termination method
mov ah,9
mov dx,offset ok_mess
int 21h
xor al,al ; Successful
Exit:
mov ah,4ch
int 21h
Init proc
; Input: ax=ds, es=PSP segment, SS:SP as set by DOS
; Output: SS:SP adjusted, CF=0 if resize is successful
;
mov bx,ss
sub bx,ax
shl bx,4
cli
mov ss,ax ; Load stack pointer
add sp,bx
sti
mov bx,sp
add bx,15 ; Round up to next paragraph
shr bx,4
add ax,bx ; AX = SS + SP / 16 = segment address
; of the end of the program space
mov bx,es
sub ax,bx ; AX = required ammount of paragraphs
mov bx,ax
mov ah,4ah
int 21h ; Resize program
ret
Init endp
end Start